home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / VU External Tool libs / MemoryMonitorOperations.Lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  9.0 KB  |  250 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:    MemoryMonitorOperations.Lib
  5. #
  6. #    Contains:    Tasks which extend the basic functionality of the MemoryMonitor.vulib.
  7. #
  8. #    Written by:    KTA
  9. #
  10. #    Copyright:    © 1993-1997 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #        1.0.6    02/12/97    JAS        Added 'vers' resources to library.
  19. #                                    These should always match tool version when tool is revved.
  20. #         <9>     2/28/95    ML        marked
  21. #         <8>     2/16/95    KTA        _MemoryMonitor() - Fixed a couple of bugs
  22. #         <7>     2/10/95    KTA        _MemoryMonitor() - Fixed problem where gMemoryMonitorInitFlag
  23. #                                    was set incorrectly (thrown out).
  24. #         <6>     1/19/95    KTA        Changed the name of ExceptionHandler() to ExceptionDispatcher().
  25. #         <5>     1/13/95    KTA        _MemoryMonitor() - Added support for calling tasks as well as
  26. #                                    services.
  27. #         <4>    12/12/94    KTA        _MemoryMonitor() - changed match[target] to match[mouse].
  28. #         <3>    12/12/94    KTA        Added _MemoryMonitor()
  29. #         <2>     4/29/94    ML        Repaced Task with TASK
  30. #         <1>     3/28/94    KTA        Created - first checked in.
  31. #
  32. # ****************************************************************************
  33. #
  34.  
  35. ########################################################################
  36. #                            External libraries 
  37. #=======================================================================
  38. Libraries "MemoryMonitor.vulib","ExceptionHandling.Lib";
  39.  
  40. #########################################################################
  41. #            _MemoryMonitor(pServiceOrTask, pParamList, pOnTarget, pIsRetry)
  42. #========================================================================
  43. # Author:        KTA 
  44. # Description:    Does the exception handling for the MemoryMonitor.  All high level tasks
  45. #                should call this routine for MemoryMonitor tool services.  
  46. #                Handles initialization of tool automatically.
  47. # Parameters:    pServiceOrTask - Name of the Service
  48. #                pParamList - List of parameters
  49. #                pOnTarget - Flag to indicate whether the service should be performed 
  50. #                            the host or the target.  1 = target/0 = host.
  51. # Returns:        What ever the MemoryMonitor returns - list of three elements
  52. #                            { errCode, Data, [error message]}
  53. # Examples:        _MemoryMonitor('GetProcess', {'SystemZone'},1);
  54. # Assumptions:    None 
  55. #========================================================================
  56. # History:
  57. # KTA    12/12/94    Created
  58. # KTA    1/13/95        Added support for calling tasks as well as services
  59. # KTA    2/10/95        Fixed problem where gMemoryMonitorInitFlag was set incorrectly (thrown out)
  60. # ML    2/14/95        coerce pOnTarget to be either true or false, Temporarily
  61. #                    turn commandexceptions off, check scripterror, reset 
  62. #                    commandexceptions, and if necessary throw scripterror 
  63. #########################################################################
  64. TASK _MemoryMonitor(pServiceOrTask, pParamList := {}, pOnTarget := true, pIsRetry := 0)
  65. begin
  66.     Try
  67.     begin
  68.         returnVal := undefined;
  69.         ParamType := TypeOf(pServiceOrTask);
  70.         
  71.         if (ParamType = 'string') # Service Call
  72.         begin
  73.             if (pOnTarget)
  74.                 pOnTarget := true;
  75.             else
  76.                 pOnTarget := false;
  77.             if not(global gMemoryMonitorInitFlag = pOnTarget)
  78.             begin
  79.                 try
  80.                 begin
  81.                     temp := CommandExceptions(0);
  82.                     MemoryMonitorInit :=  MemoryMonitor("Initialize", pOnTarget );         # initialize MemoryMonitor
  83.                     InitError := Scripterror();
  84.                     CommandExceptions(temp);
  85.                     if (MemoryMonitorInit[1] <> 0)        # If error
  86.                     begin
  87.                         println "MemoryMonitor error ( ", MemoryMonitorInit[1], ", ",  MemoryMonitorInit[3] , " )";
  88.                         gMemoryMonitorInitFlag := undefined;
  89.                         if (CommandExceptions())
  90.                             throw InitError;
  91.                         return(MemoryMonitorInit);
  92.                     end;
  93.                     else
  94.                         gMemoryMonitorInitFlag := pOnTarget;
  95.                 end;
  96.                 catch theErr
  97.                 begin
  98.                     ExceptionDispatcher(theErr);
  99.                     return(MemoryMonitorInit);
  100.                 end;
  101.             end;
  102.  
  103.             try
  104.             begin
  105.                 NumParams := Card(pParamList);
  106.                 switch NumParams
  107.                 begin
  108.                     case 0:                    # 0 parameters
  109.                         returnVal := MemoryMonitor(pServiceOrTask); 
  110.                     case 1:                    # 1 parameter
  111.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1]); 
  112.                     case 2:                    # 2 parameters
  113.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1], pParamList[2]); 
  114.                     case 3:                    # 3 parameters
  115.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3]); 
  116.                     case 4:                    # 4 parameters
  117.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4]); 
  118.                     case 5:                    # 5 parameters
  119.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5]); 
  120.                     case 6:                    # 6 parameters
  121.                         returnVal := MemoryMonitor(pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5], pParamList[6]); 
  122.                     default:                # error
  123.                         println "Error - unsupported number of parameters - {NumParams}";
  124.                 end;
  125.         
  126.                 if (returnVal[1] <> 0)        # If error
  127.                 begin
  128.                     if(returnVal[1] = -1) and not (pIsRetry)    # Not initialized, and haven't retried already
  129.                     begin
  130.                         global gMemoryMonitorInitFlag := undefined;
  131.                         returnVal := _MemoryMonitor(pServiceOrTask, pParamList, pOnTarget, 1);
  132.                     end;
  133.                 end;
  134.                 else if(pServiceOrTask = 'Quit')        # Reset the global gMemoryMonitorInitFlag when we quit
  135.                     global gMemoryMonitorInitFlag := undefined;
  136.             
  137.             end;
  138.             catch theErr
  139.             begin
  140.                 if(theErr = -1220) and not (pIsRetry)
  141.                 begin
  142.                     global gMemoryMonitorInitFlag := undefined;
  143.                     returnVal := _MemoryMonitor(pServiceOrTask, pParamList, pOnTarget, 1);
  144.                 end;
  145.                 else
  146.                     exceptionDispatcher(theErr);
  147.             end;
  148.         end;
  149.         else if(ParamType = 'task')
  150.         begin
  151.             NumParams := Card(pParamList);
  152.             switch NumParams 
  153.             begin
  154.                 case 0:                    # 0 parameters
  155.                     returnVal := call (pServiceOrTask); 
  156.                 case 1:                    # 1 parameter
  157.                     returnVal := call (pServiceOrTask, pParamList[1]); 
  158.                 case 2:                    # 2 parameters
  159.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2]); 
  160.                 case 3:                    # 3 parameters
  161.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3]); 
  162.                 case 4:                    # 4 parameters
  163.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4]); 
  164.                 case 5:                    # 5 parameters
  165.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5]); 
  166.                 case 6:                    # 6 parameters
  167.                     returnVal := call (pServiceOrTask, pParamList[1], pParamList[2], pParamList[3], pParamList[4], pParamList[5], pParamList[6]); 
  168.                 default:                # error
  169.                     println "Error - unsupported number of parameters - {NumParams}";
  170.             end;
  171.         end;
  172.         
  173.         if(pOnTarget)            # To cause target errors to throw if Xtools are called
  174.             match[mouse];
  175.             
  176.         return(returnVal);
  177.     end;
  178.     Catch theError
  179.         ExceptionDispatcher(theError);
  180. end;
  181.  
  182.  
  183.  
  184. #########################################################################
  185. #                        MemoryMonitorInit(pOnTarget)
  186. #========================================================================
  187. # Author:        KTA
  188. # Description:    Makes a call to initialize MemoryMonitor.  Defalut is to 
  189. #                initalize it on the Target.
  190. # Parameters:    pOnTarget  - True means Memory Monitor will be initialized 
  191. #                            on the Target.
  192. #                            - False means Memory Monitor will be initialized 
  193. #                            on the Host.
  194. # Returns:        1 - initialization was successful.
  195. #                0 - initialization failed
  196. # Examples:        MemoryMonitorInit();
  197. # Assumptions:    
  198. #========================================================================
  199. # History:
  200. # KTA    3/08/94        Created
  201. # KTA    12/12/94    Added calls to _MemoryMonitor()
  202. #########################################################################
  203. TASK MemoryMonitorInit(pOnTarget := True)
  204. begin
  205.     returnVal := 0;
  206.     
  207.     initResult := _MemoryMonitor('Initialize',{pOnTarget});
  208.     if(initResult[1] <> 0)
  209.     begin 
  210.         println "Problem initializing Memory Monitor";        # print error
  211.         println "Error ", initResult[1], ". ",  initResult[3] ;
  212.     end;
  213.     else
  214.     begin
  215.         returnVal := 1;
  216.     end;
  217.     return(returnVal);
  218. end;
  219.  
  220. #########################################################################
  221. #                        MemoryMonitorQuit()
  222. #========================================================================
  223. # Author:        KTA
  224. # Description:    Makes a call to quit MemoryMonitor.  
  225. # Parameters:    none
  226. # Returns:        1 - quitting was successful.
  227. #                0 - quitting failed
  228. # Examples:        MemoryMonitorQuit();
  229. # Assumptions:    
  230. #========================================================================
  231. # History:
  232. # KTA    3/08/94        Created
  233. # KTA    12/12/94    Added calls to _MemoryMonitor()
  234. #########################################################################
  235. TASK MemoryMonitorQuit()
  236. begin
  237.     returnVal := 0;
  238.     QuitResult := _MemoryMonitor('Quit');
  239.     if(QuitResult[1] <> 0)
  240.     begin 
  241.         println "Problem quitting Memory Monitor";        # print error
  242.         println "Error ", QuitResult[1], ". ",  QuitResult[3] ;
  243.     end;
  244.     else
  245.     begin
  246.         returnVal := 1;
  247.     end;
  248.     return(returnVal);
  249. end;
  250.